package com.cy.jxc.controller;

import com.cy.jxc.entity.User;
import com.cy.jxc.service.UserSettingService;
import com.cy.jxc.utils.ShiroUtils;
import com.cy.jxc.vo.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserSettingController {
    @Autowired
    private UserSettingService userSettingService;






    @RequestMapping("/findUserByName")
    public JsonResult FindUserByName(String username){

        User user = userSettingService.findByUsername(username);
        return new JsonResult(user);
    }

    //    @RequestMapping("/updateByUsername")
//    public JsonResult UpdateByUsername(String  username,User user){
//        username = ShiroUtils.getUserName();
//
//
//        userSettingService.UpdateByUsername(username,user);
//        return new JsonResult("update ok");
//    }
    @RequestMapping("/updateUsername")
    public JsonResult UpdateUsername(String newName,String username){
        username = ShiroUtils.getUserName();
        userSettingService.UpdateUsername(newName, username);
        return new JsonResult("update ok");
    }
    @RequestMapping("/updatePsw")
    public JsonResult UpdatePsw(String password,String username){
        username = ShiroUtils.getUserName();
        userSettingService.updatePsw(password, username);
        return new JsonResult("update ok");
    }
    @RequestMapping("/updateEmail")
    public JsonResult UpdateEmail(String email,String username){
        username = ShiroUtils.getUserName();
        userSettingService.updateEmail(email, username);
        JsonResult result=new JsonResult("update ok");
        result.setStatus(3);
        return result;
    }
}
